package com.gill.touka.feign.fallback;

import com.gill.touka.domain.dto.UserDTO;
import com.gill.touka.feign.client.UserCenterFeignClient;
import feign.hystrix.FallbackFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Date;
/**
 * feign进行RPC失败后执行
 */
@Slf4j
@Component
public class FeignFallbackFactory implements FallbackFactory<UserCenterFeignClient> {
    @Override
    public UserCenterFeignClient create(Throwable throwable) {
        return new UserCenterFeignClient() {
            @Override
            public UserDTO findById(Integer id) {
                log.warn("feign调用远程接口失败：异常信息如下",throwable);//以下信息没有任何含义，只是为了方便测试
                UserDTO result = new UserDTO();
                result.setId(0);
                result.setWxId("feign调用远程服务失败信息");
                result.setWxNickname("feign调用远程服务失败信息。。。。。。。feign调用远程服务失败信息。。。");
                result.setRoles("feign调用远程服务失败信息");
                result.setAvatarUrl("feign调用远程服务失败信息");
                result.setCreateTime(new Date());
                result.setUpdateTime(new Date());
                result.setBonus(0);
                return result;
            }

            @Override
            public UserDTO testGet(UserDTO userDTO) {
                return null;
            }

            @Override
            public UserDTO testPost(UserDTO userDTO) {
                return null;
            }
        };
    }
}
